home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
132
< prev
next >
Wrap
Text File
|
1996-08-06
|
2KB
|
50 lines
Path: fsgm01.fnal.gov!not-for-mail
From: b91926@fsgm01.fnal.gov (David Sachs)
Newsgroups: comp.std.c
Subject: Re: ... char * * promotion to char const * const * ...
Date: 17 Jan 1996 16:45:23 -0600
Organization: FERMILAB, Batavia, IL
Message-ID: <4dju63$9mq@fsgm01.fnal.gov>
References: <4dgj8q$qin@unix.sri.com> <KANZE.96Jan17121659@slsvewt.lts.sel.alcatel.de> <DLBzGB.J60@polo.demon.co.uk>
Reply-To: sachs@fnal.fnal.gov
NNTP-Posting-Host: fsgm01.fnal.gov
X-Newsreader: NN version 6.5.0 #4 (NOV)
john@polo.demon.co.uk (John Winters) writes:
>In article <KANZE.96Jan17121659@slsvewt.lts.sel.alcatel.de>,
>James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de> wrote:
>[snip]
>>
>>Originally, the C standard was going to allow this; in fact, it was
>>going to allow all casts which added const anywhere in the type. Then
>>someone pointed out that the conversion 'char ** -> char *const *' was
>>unsafe. As a result, the wording was changed to only allow adding the
>>const at the top level.
>Interesting. Could you enlighten us (well, me anyway) as to *why* it
>is unsafe. I don't find it immediately obvious.
Actually 'char ** -> char *const *' is a safe conversion. The related
UNSAFE conversion is 'char ** -> const char **'. This is unsafe
because you could use this conversion to change a constant char.
e.g.
const char a = 'a';
char b;
char *bb = b;
char **bbb = bb;
const char** ccc;
/* The following statement is an illegal cnversion */
ccc = bbb;
/* Assume the preceding conversion were legal - we could now do */
*ccc = &a;
/* bb now points to a */
*bb = 'b';
/* We have just changed the constant character variable a */
--
** The Klingons' favorite food was named by the first earthling to see it **
David Sachs - Fermilab, HPPC MS369 - P. O. Box 500 - Batavia, IL 60510
Voice: 1 708 840 3942 Deparment Fax: 1 708 840 3785